package com.kgcx.order.service;

import com.kgcx.common.eum.OrderEnum;
import com.kgcx.order.domain.Order;
import com.kgcx.order.domain.OrderLog;
import com.kgcx.order.mapper.OrderLogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.net.InetAddress;
import java.net.UnknownHostException;

@Service
public class OrderLogService {
    @Autowired
    private OrderLogMapper mapper;

    public void add(OrderLog record) {
        mapper.insertSelective(record);
    }

    public void log(Order order, String optContent)
    {
        OrderLog oLog = new OrderLog();
        oLog.setOrderNo(order.getOrderNo());
        oLog.setOrderState(order.getOrderState());
        oLog.setOptType(OrderEnum.OPT_TYPE_UPDATE);
        oLog.setOptContent(optContent);
        String ip = "";
        try{ ip = InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException ex) { }
        oLog.setIp(ip);
        this.add(oLog);
    }
}
